package com.aurora.model.vo.rabbitMQ;

/**
 * @author liu jun
 */

import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import javax.annotation.Resource;

import static com.aurora.constant.MQPrefixConst.FANOUT_EXCHANGE;
/**
 *
 * @author liujun
 * @date 2022/11/24
 */
@Data
@NoArgsConstructor
public class FanoutSender {
    private static final Logger LOGGER = LoggerFactory.getLogger(FanoutSender.class);
    @Resource
    private RabbitTemplate template;


    public void send(int index) {
        StringBuilder builder = new StringBuilder("Hello");
        int limitIndex = index % 3 + 1;
        for (int i = 0; i < limitIndex; i++) {
            builder.append('.');
        }
        builder.append(index + 1);
        String message = builder.toString();
        template.convertAndSend(FANOUT_EXCHANGE, "", message);
        LOGGER.info(" [x] Sent '{}'", message);
    }

}
